package com.maori.languageapp.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

	// Database Name
	private static final String DATABASE_NAME = "maorilanguageapp.db";
	// Master Tables
	private String USER_TABLE = "User";
	private String CONTENTTYPE_TABLE = "Content_type";
	private String DIALACT_TABLE = "Dialact";
	private String LANGUAGE_TABLE = "Language";
	private String MEDIA_TABLE = "Media";
	private String NODECATEGORY_TABLE = "Node_Category";
	private String PHRASE_TABLE = "Phrase";
	private String SONG_TABLE = "Song";
	private String STORY_TABLE = "Story";
	private String WORD_TABLE = "Word";
	private String IDIOM_TABLE = "Idiom";
	private String BOOKMARK_TABLE = "Bookmark";

	private String MEDIA_FILE_URL = "MediaFileUrl";

	// Database Version
	private static final int DATABASE_VERSION = 1;
	private static final String TAG = null;

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// this.myContext = context;
	}

	@Override
	public void onCreate(SQLiteDatabase mydb) {
		try {
			Log.v(TAG, "onCreate Call");
			mydb.execSQL("create table if not exists "
					+ USER_TABLE
					+ "(_id integer primary key autoincrement,first_name text not null, last_name text not null, tribe text not null, email text not null, username text not null, password text not null, role text not null, user_created text not null, last_logedIn text not null, status text not null, UID text not null, MID text not null, LatestDownload text not null,Activate text not null,Remember text not null,BookmarkCount text not null,MyRecordsCount text not null);");

			mydb.execSQL("create table if not exists "
					+ CONTENTTYPE_TABLE
					+ "(_id integer primary key autoincrement,content_type_id text not null,content text not null);");

			mydb.execSQL("create table if not exists "
					+ DIALACT_TABLE
					+ "(_id integer primary key autoincrement,dialact_id text not null,dialact text not null);");

			mydb.execSQL("create table if not exists "
					+ LANGUAGE_TABLE
					+ "(_id integer primary key autoincrement,LID text not null,Language text not null);");

			mydb.execSQL("create table if not exists "
					+ MEDIA_TABLE
					+ "(_id integer primary key autoincrement,MID text not null,media_type text not null);");

			mydb.execSQL("create table if not exists "
					+ NODECATEGORY_TABLE
					+ "(_id integer primary key autoincrement,node_cat_id text not null,node_category text not null,NCMID text not null);");

			mydb.execSQL("create table if not exists "
					+ MEDIA_FILE_URL
					+ "(_id integer primary key autoincrement,McategoryId text not null,MediaFileName text not null,ResouceDeviceUrl text not null,ResouceServerUrl text not null,UploadingState text not null);");

			mydb.execSQL("create table if not exists "
					+ WORD_TABLE
					+ "(_id integer primary key autoincrement,WordID text not null,LID text not null,NID text not null,word text not null,Otherwords text not null, activeState text not null);");

			mydb.execSQL("create table if not exists "
					+ IDIOM_TABLE
					+ "(_id integer primary key autoincrement,IdiomID text not null,LID text not null,NID text not null,Idiom text not null,Otheridioms text not null, activeState text not null);");
			
			mydb.execSQL("create table if not exists "
					+ PHRASE_TABLE
					+ "(_id integer primary key autoincrement,PhraseID text not null,LID text not null,NID text not null,Phrase text not null,OtherPhrase text not null, activeState text not null);");

			mydb.execSQL("create table if not exists "
					+ SONG_TABLE
					+ "(_id integer primary key autoincrement,SongID text not null,LID text not null,NID text not null,song_title text not null,song_content text not null,other_song_title text not null,other_song_content text not null,activeState text not null);");

			mydb.execSQL("create table if not exists "
					+ STORY_TABLE
					+ "(_id integer primary key autoincrement,StoryID text not null,LID text not null,NID text not null,story_title text not null,story_content text not null,other_story_title text not null,other_story_content text not null,activeState text not null);");
			
			mydb.execSQL("create table if not exists "
					+ BOOKMARK_TABLE
					+ "(_id integer primary key autoincrement,NID text not null,english_title text not null,english_det text not null,maori_title text not null,maori_det text not null,category text not null);");
			
		} catch (Exception e) {
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// on upgrade drop older tables
		Log.v(TAG, "onUpgrade Call");
		Log.v(TAG, "oldVersion :" + oldVersion);
		Log.v(TAG, "newVersion :" + newVersion);
	}

}
